<?php

namespace App\Http\Requests\Backend;

use App\Models\WechatMenu;
use Illuminate\Foundation\Http\FormRequest;

/**
 * Class StoreWechatMenu
 * @package App\Http\Requests\Backend
 */
class StoreWechatMenu extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        if ($this->type == 'click') {
            return WechatMenu::$clickMenuRules;
        } elseif ($this->type == 'view') {
            return WechatMenu::$viewMenuRules;
        } elseif ($this->type == 'media_id') {
            return WechatMenu::$mediaMenuRules;
        } elseif ($this->type == 'miniprogram') {
            return WechatMenu::$miniprogramMenuRules;
        } else {
            return WechatMenu::$mainMenuRules;
        }
    }

    /**
     * @return array
     */
    public function attributes()
    {
        return [
            'name' => '菜单名称',
            'key' => 'key',
            'text' => '回复文本',
            'url' => '跳转链接',
            'media_id' => '素材id',
            'pagepath' => '小程序路径',
            'miniprogram_appid' => '小程序appid'
        ];
    }

    /**
     * @return array
     */
    public function messages()
    {
        return [
            'name.required' => '请填写:attribute',
            'key.required' => '请填写:attribute',
            'text.required' => '请填写:attribute',
            'url.required' => '请填写:attribute',
            'url.url' => ':attribute格式错误',
            'media_id.required' => '请填写:attribute',
            'pagepath.required' => '请填写:attribute',
            'miniprogram_appid.required' => '请填写:attribute'
        ];
    }
}
